/*
 * pattern.h
 *
 *  Created on: 2012-12-12
 *      Author: shane
 */

#ifndef PATTERN_H_
#define PATTERN_H_

#include "geometry.h"
#include "material.h"
#include "EME_exception.h"

namespace EME
{
class EME_pattern_logic_error: public EME_logic_error
{
public:
	inline explicit EME_pattern_logic_error(const std::string&s,
			unsigned int code) :
			EME_logic_error(s, code)
	{
	}
	;
};

class EME_pattern_runtime_error: public EME_runtime_error
{
public:
	inline explicit EME_pattern_runtime_error(const std::string&s,
			unsigned int code) :
			EME_runtime_error(s, code)
	{
	}
	;
};
struct block
{
	material* mat; ///< actually, we will never use new here
	geo_object* geo; ///< actually, we will never use new here
};
class pattern
{
private:
	double xmin;
	double xmax;
	double ymin;
	double ymax;
	bool if_lossy;
	std::vector<block> blocks;
	material* default_mat;
public:
	inline pattern(material *const &default_mat_in) :
			xmin(1e10), xmax(-1e10), ymin(1e10), ymax(-1e10), if_lossy(default_mat_in->if_lossy()), blocks(
					std::vector<block>()),default_mat(default_mat_in)
	{
	}
	inline virtual void change_default_mat(material *const &default_mat_in){
		default_mat=default_mat_in;
		if_lossy=default_mat->if_lossy();
		for (std::vector<block>::iterator i = blocks.begin(); i != blocks.end(); ++i)
			{
				if ((*i).mat->if_lossy())
					if_lossy=true;
			}
	}
	;
	void push_back(const block& b);
	void insert(const std::vector<block>::size_type& index, const block& b);
	void remove(const std::vector<block>::size_type& index);
	virtual material* material_fun(double x, double y);
	inline virtual ~pattern()
	{
	}
	;
};
}

#endif /* PATTERN_H_ */
